const codeStr = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'

/**
 * 生成6位随机数
 * @description 生成6位随机数
 */
const uuid = function () {
  let str = ''
  // 验证码有几位就循环几次
  for (let i = 0; i < 8; i++) {
    const ran = _getRandom(0, 62)
    str += codeStr.charAt(ran)
  }

  return str
}

function _getRandom (n, m) { // param: (Number, Number)
  n = Number(n)
  m = Number(m)
  // 确保 m 始终大于 n
  if (n > m) {
    const temp = n
    n = m
    m = temp
  }

  return Math.floor(Math.random() * (m - n) + n)
}

export default uuid
